#!/usr/local/bin/tea

//system.stdout("Content-type: text/plain\n\n");
require.paths.unshift("./code");

require('http');
// HACK

var ows=Array.prototype.globalStore;
if (!ows) {
	ows=require('server/server').createServer();
	Array.prototype.globalStore=ows;
	ows.init();
}
if (system.env.TERM || system.args.length>1) {
	ows.work();
} else {
	try {
		ows.work(request,response);
	} catch(e) {
		if (typeof e=="object") {
			system.stdout("Content-type: text/plain\n\nCORE ERROR\n");
			for (var k in e) {
				system.stdout(k+"="+e[k]+"\n");
			}
		} else {
			system.stdout("Content-type: text/plain\n\nCORE ERROR\n"+e+"\n");
		}
	}
}
